home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / gsm / inc / private.h < prev    next >
C/C++ Source or Header  |  2000-05-18  |  7KB  |  249 lines

  1. /*
  2.  * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3.  * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
  4.  * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5.  */
  6.  
  7. /*$Header: /home/kbs/jutta/src/gsm/gsm-1.0/inc/RCS/private.h,v 1.2 1993/01/29 18:25:27 jutta Exp $*/
  8.  
  9. #ifndef    PRIVATE_H
  10. #define    PRIVATE_H
  11.  
  12. typedef short            word;        /* 16 bit signed int    */
  13. typedef int            longword;    /* 32 bit signed int    */
  14.  
  15. typedef unsigned short        uword;        /* unsigned word    */
  16. typedef unsigned int        ulongword;    /* unsigned longword    */
  17.  
  18. struct gsm_state {
  19.  
  20.     word        dp0[ 280 ];
  21.  
  22.     word        z1;        /* preprocessing.c, Offset_com. */
  23.     longword    L_z2;        /*                  Offset_com. */
  24.     int        mp;        /*                  Preemphasis    */
  25.  
  26.     word        u[8];        /* short_term_aly_filter.c    */
  27.     word        LARpp[2][8];     /*                              */
  28.     word        j;        /*                              */
  29.  
  30.     word        nrp; /* 40 */    /* long_term.c, synthesis    */
  31.     word        v[9];        /* short_term.c, synthesis    */
  32.     word        msr;        /* decoder.c,    Postprocessing    */
  33.  
  34.     char        verbose;    /* only used if !NDEBUG        */
  35.     char        fast;        /* only used if FAST        */
  36.  
  37. };
  38.  
  39.  
  40. #define    MIN_WORD    (-32768)
  41. #define    MAX_WORD    ( 32767)
  42.  
  43. #define    MIN_LONGWORD    ((-2147483647)-1)
  44. #define    MAX_LONGWORD    ( 2147483647)
  45.  
  46. #ifdef    SASR        /* >> is a signed arithmetic shift right */
  47. #undef    SASR
  48. #define    SASR(x, by)    ((x) >> (by))
  49. #endif    /* SASR */
  50.  
  51.  
  52. #include "proto.h"
  53.  
  54. /*
  55.  *    Prototypes from add.c
  56.  */
  57. extern word    gsm_mult     P((word a, word b));
  58. extern longword gsm_L_mult     P((word a, word b));
  59. extern word    gsm_mult_r    P((word a, word b));
  60.  
  61. extern word    gsm_div      P((word num, word denum));
  62.  
  63. extern word    gsm_add     P(( word a, word b ));
  64. extern longword gsm_L_add     P(( longword a, longword b ));
  65.  
  66. extern word    gsm_sub     P((word a, word b));
  67. extern longword gsm_L_sub     P((longword a, longword b));
  68.  
  69. extern word    gsm_abs     P((word a));
  70.  
  71. extern word    gsm_norm     P(( longword a ));
  72.  
  73. extern longword gsm_L_asl      P((longword a, int n));
  74. extern word    gsm_asl     P((word a, int n));
  75.  
  76. extern longword gsm_L_asr      P((longword a, int n));
  77. extern word    gsm_asr      P((word a, int n));
  78.  
  79. /*
  80.  *  Inlined functions from add.h 
  81.  */
  82.  
  83. /* 
  84.  * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *)    \
  85.  *    (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
  86.  */
  87. #define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */    \
  88.     (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
  89.  
  90. # define GSM_MULT(a,b)     /* word a, word b, !(a == b == MIN_WORD) */    \
  91.     (SASR( ((longword)(a) * (longword)(b)), 15 ))
  92.  
  93. # define GSM_L_MULT(a, b) /* word a, word b */    \
  94.     (((longword)(a) * (longword)(b)) << 1)
  95.  
  96. # define GSM_L_ADD(a, b)    \
  97.     ( (a) <  0 ? ( (b) >= 0 ? (a) + (b)    \
  98.          : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
  99.            >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 )   \
  100.     : ((b) <= 0 ? (a) + (b)   \
  101.               : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
  102.             ? MAX_LONGWORD : utmp))
  103.  
  104. /*
  105.  * # define GSM_ADD(a, b)    \
  106.  *     ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
  107.  *     ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
  108.  */
  109. /* Nonportable, but faster: */
  110.  
  111. #define    GSM_ADD(a, b)    \
  112.     ((unsigned)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
  113.         MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
  114.  
  115. # define GSM_SUB(a, b)    \
  116.     ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
  117.     ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
  118.  
  119. # define GSM_ABS(a)    ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
  120.  
  121. /* Use these if necessary:
  122.  
  123. # define GSM_MULT_R(a, b)    gsm_mult_r(a, b)
  124. # define GSM_MULT(a, b)        gsm_mult(a, b)
  125. # define GSM_L_MULT(a, b)    gsm_L_mult(a, b)
  126.  
  127. # define GSM_L_ADD(a, b)    gsm_L_add(a, b)
  128. # define GSM_ADD(a, b)        gsm_add(a, b)
  129.  
  130. # define GSM_ABS(a)        gsm_abs(a)
  131.  
  132. */
  133.  
  134. /*
  135.  *  More prototypes from implementations..
  136.  */
  137. extern void Gsm_Coder P((
  138.         struct gsm_state    * S,
  139.         word    * s,    /* [0..159] samples        IN    */
  140.         word    * LARc,    /* [0..7] LAR coefficients    OUT    */
  141.         word    * Nc,    /* [0..3] LTP lag        OUT     */
  142.         word    * bc,    /* [0..3] coded LTP gain    OUT     */
  143.         word    * Mc,    /* [0..3] RPE grid selection    OUT     */
  144.         word    * xmaxc,/* [0..3] Coded maximum amplitude OUT    */
  145.         word    * xMc    /* [13*4] normalized RPE samples OUT    */));
  146.  
  147. extern void Gsm_Long_Term_Predictor P((        /* 4x for 160 samples */
  148.         struct gsm_state * S,
  149.         word    * d,    /* [0..39]   residual signal    IN    */
  150.         word    * dp,    /* [-120..-1] d'        IN    */
  151.         word    * e,    /* [0..40]             OUT    */
  152.         word    * dpp,    /* [0..40]             OUT    */
  153.         word    * Nc,    /* correlation lag        OUT    */
  154.         word    * bc    /* gain factor            OUT    */));
  155.  
  156. extern void Gsm_LPC_Analysis P((
  157.         struct gsm_state * S,
  158.         word * s,     /* 0..159 signals    IN/OUT    */
  159.             word * LARc));   /* 0..7   LARc's    OUT    */
  160.  
  161. extern void Gsm_Preprocess P((
  162.         struct gsm_state * S,
  163.         word * s, word * so));
  164.  
  165. extern void Gsm_Encoding P((
  166.         struct gsm_state * S,
  167.         word    * e,    
  168.         word    * ep,    
  169.         word    * xmaxc,
  170.         word    * Mc,    
  171.         word    * xMc));
  172.  
  173. extern void Gsm_Short_Term_Analysis_Filter P((
  174.         struct gsm_state * S,
  175.         word    * LARc,    /* coded log area ratio [0..7]  IN    */
  176.         word    * d    /* st res. signal [0..159]    IN/OUT    */));
  177.  
  178. extern void Gsm_Decoder P((
  179.         struct gsm_state * S,
  180.         word    * LARcr,    /* [0..7]        IN    */
  181.         word    * Ncr,        /* [0..3]         IN     */
  182.         word    * bcr,        /* [0..3]        IN    */
  183.         word    * Mcr,        /* [0..3]         IN     */
  184.         word    * xmaxcr,    /* [0..3]        IN     */
  185.         word    * xMcr,        /* [0..13*4]        IN    */
  186.         word    * s));        /* [0..159]        OUT     */
  187.  
  188. extern void Gsm_Decoding P((
  189.         struct gsm_state * S,
  190.         word     xmaxcr,
  191.         word    Mcr,
  192.         word    * xMcr,      /* [0..12]        IN    */
  193.         word    * erp));     /* [0..39]        OUT     */
  194.  
  195. extern void Gsm_Long_Term_Synthesis_Filtering P((
  196.         struct gsm_state* S,
  197.         word    Ncr,
  198.         word    bcr,
  199.         word    * erp,        /* [0..39]          IN     */
  200.         word    * drp));     /* [-120..-1] IN, [0..40] OUT     */
  201.  
  202. extern void Gsm_Short_Term_Synthesis_Filter P((
  203.         struct gsm_state * S,
  204.         word    * LARcr,     /* log area ratios [0..7]  IN    */
  205.         word    * drp,        /* received d [0...39]       IN    */
  206.         word    * s));        /* signal   s [0..159]      OUT    */
  207.  
  208. extern void Gsm_Update_of_reconstructed_short_time_residual_signal P((
  209.         word    * dpp,        /* [0...39]    IN    */
  210.         word    * ep,        /* [0...39]    IN    */
  211.         word    * dp));        /* [-120...-1]  IN/OUT     */
  212.  
  213. /*
  214.  *  Tables from table.c
  215.  */
  216. #ifndef    GSM_TABLE_C
  217.  
  218. extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
  219. extern word gsm_INVA[8];
  220. extern word gsm_DLB[4], gsm_QLB[4];
  221. extern word gsm_H[11];
  222. extern word gsm_NRFAC[8];
  223. extern word gsm_FAC[8];
  224.  
  225. #endif    /* GSM_TABLE_C */
  226.  
  227. /*
  228.  *  Debugging
  229.  */
  230. #ifdef NDEBUG
  231.  
  232. #    define    gsm_debug_words(a, b, c, d)        /* nil */
  233. #    define    gsm_debug_longwords(a, b, c, d)        /* nil */
  234. #    define    gsm_debug_word(a, b)            /* nil */
  235. #    define    gsm_debug_longword(a, b)        /* nil */
  236.  
  237. #else    /* !NDEBUG => DEBUG */
  238.  
  239.     extern void  gsm_debug_words     P((char * name, int, int, word *));
  240.     extern void  gsm_debug_longwords P((char * name, int, int, longword *));
  241.     extern void  gsm_debug_longword  P((char * name, longword));
  242.     extern void  gsm_debug_word      P((char * name, word));
  243.  
  244. #endif /* !NDEBUG */
  245.  
  246. #include "unproto.h"
  247.  
  248. #endif    /* PRIVATE_H */
  249.